********************************************************************************			
********************* Recode stacked data for conditional logit ****************
********************************************************************************
* Start with stacked data for scalometer analysis
		use "ZA6804_v6-0-0_processed_stacked_scalo.dta", clear

* Note: we need to do some of the recoding differently, as the vote variable necessitates that we treat CDU and CSU as one category
		
	*** drop the CSU entry
		drop if obs_party==2
	
	*** change label for obs_party=1 accordingly
		label define obs_party 1 "UNION", modify
		
	*** vote choice 
		* (note: no seperate entry for CSU, here we need to treat CDU/CSU as one category)
		gen vote = 0 if w8_vote < . & obs_party != 2
		replace vote = 1 if obs_party == 1 & w8_vote == 1
		replace vote = 1 if obs_party == 3 & w8_vote == 4
		replace vote = 1 if obs_party == 4 & w8_vote == 5
		replace vote = 1 if obs_party == 5 & w8_vote == 6
		replace vote = 1 if obs_party == 6 & w8_vote == 7
		replace vote = 1 if obs_party == 7 & w8_vote == 322

	*** vote intention
		* (note: no seperate entry for CSU, here we need to treat CDU/CSU as one category)
		gen voteint = 0 if w7_voteint < . & obs_party != 2
		replace voteint = 1 if obs_party == 1 & w7_voteint == 1
		replace voteint = 1 if obs_party == 3 & w7_voteint == 4
		replace voteint = 1 if obs_party == 4 & w7_voteint == 5
		replace voteint = 1 if obs_party == 5 & w7_voteint == 6
		replace voteint = 1 if obs_party == 6 & w7_voteint == 7
		replace voteint = 1 if obs_party == 7 & w7_voteint == 322
		
	*** replace CDU values with CSU values for Bavarian voters 
		* (based on Bundesland information from wave 1; note that this may be imperfect since people may move) 
		* (there is also such Bundesland information from wave 8)
		* (though it is not clear which is better as this is about where people were eligible to vote in the Bundestagswahl 2017)
		
		* perceived party positions
		replace w7_party_highertaxes = w7_highertaxes_csu if obs_party == 1 & kp1_2601 == 9
		replace w7_party_migrrestr = w7_migrrestr_csu if obs_party == 1 & kp1_2601 == 9
		
		replace w7_party_highertaxes_st = w7_highertaxes_csu_st if obs_party == 1 & kp1_2601 == 9
		replace w7_party_migrrestr_st = w7_migrrestr_csu_st if obs_party == 1 & kp1_2601 == 9
		
		replace w7_party_lr = kp7_1490b if obs_party == 1 & kp1_2601 == 9
		drop w7_party_lr_st
		gen w7_party_lr_st = (w7_party_lr-1)/10
		
		* skalometer
		replace skalometer = kp7_430b if obs_party == 1 & kp1_2601 == 9

		
	*** drop previous variables which are not accurate for the stacked data with one entry for UNION
		drop dist_subj_migration dist_subj_econ dist_subj_leftright
		drop w7_party_highertaxes_dum w7_party_migrrestr_dum
		drop w7_party_leftauth w7_party_rightauth w7_party_rightlib w7_party_leftlib
		
	*** Compute derived perceived party variables new (now that the entry for UNION has been changed)	
		
		* perceived distance 
		gen w7_dist_subj_migration=abs(w7_migrrestr_ego-w7_party_migrrestr)
		gen w7_dist_subj_econ=abs(w7_highertaxes_ego-w7_party_highertaxes)
		gen w7_dist_subj_leftright=abs(w7_leftright-w7_party_lr)
		
		gen w7_dist_subj_migration_st=w7_dist_subj_migration/6
		gen w7_dist_subj_econ_st=w7_dist_subj_econ/6
		gen w7_dist_subj_leftright_st=w7_dist_subj_leftright/10
					
		* dichotomize perceived party position
		recode w7_party_highertaxes (1 2 3 4=0) (5 6 7=1), gen(w7_party_highertaxes_dum)
		recode w7_party_migrrestr (1 2 3 4=0) (5 6 7=1), gen(w7_party_migrrestr_dum)
		
		* perception of left-authoritarian position
		gen w7_party_leftauth=0 if w7_party_highertaxes<. & w7_party_migrrestr<.
		replace w7_party_leftauth=1 if w7_party_highertaxes_dum==1 & w7_party_migrrestr_dum==1
	
			* and other quadrants
			gen w7_party_rightauth=0 if w7_party_highertaxes<. & w7_party_migrrestr<.
			replace w7_party_rightauth=1 if w7_party_highertaxes>=1 & w7_party_highertaxes<=3 & w7_party_migrrestr>=5 & w7_party_migrrestr<=7
			
			gen w7_party_rightlib=0 if w7_party_highertaxes<. & w7_party_migrrestr<.
			replace w7_party_rightlib=1 if w7_party_highertaxes>=1 & w7_party_highertaxes<=3 & w7_party_migrrestr>=1 & w7_party_migrrestr<=3
			
			gen w7_party_leftlib=0 if w7_party_highertaxes<. & w7_party_migrrestr<.
			replace w7_party_leftlib=1 if w7_party_highertaxes>=5 & w7_party_highertaxes<=7 & w7_party_migrrestr>=1 & w7_party_migrrestr<=3

		
	*** create interactions terms for regression models		
		* we need to create the interaction terms manually as cmclogit won't accept them (constituent variable salience does not vary within individuals)
		
		* position dummies-salience interactions
		gen party_highertaxesXeconMIP = w7_party_highertaxes_dum * w7_mip_econ	
		gen party_migrrestrXmigrMIP = w7_party_migrrestr_dum * w7_mip_immi		
		
		* position-salience interactions
		gen w7_party_highertaxes_stXeconMIP = w7_party_highertaxes_st * w7_mip_econ
		gen w7_party_migrrestr_stXmigrMIP = w7_party_migrrestr_st * w7_mip_immi
		
		* distance-salience interactions
		gen w7_dist_s_econXeconMIP = w7_dist_subj_econ_st * w7_mip_econ
		gen w7_dist_s_migrationXmigrMIP = w7_dist_subj_migration_st * w7_mip_immi
			
		* perceived left-right position X left/right dummy
		gen w7_party_lr_stXleft=w7_party_lr_st*w7_left
		gen w7_party_lr_stXright=w7_party_lr_st*w7_right
		
		
	*** label some variables
		label variable w7_party_highertaxes_dum "Party perceived as economically left"
		label variable w7_party_migrrestr_dum "Party perceived as restrictive on migration"
		label variable w7_party_leftauth "Party perceived as left-authoritarian"
		label variable w7_party_rightauth "Party perceived as right-authoritarian"
		label variable w7_party_leftlib "Party perceived as left-libertarian"
		label variable w7_party_rightlib "Party perceived as right-libertarian"
		label variable party_highertaxesXeconMIP "Party economically left X MIP economic"
		label variable party_migrrestrXmigrMIP "Party restrict migration X MIP migration"	
		
		label variable w7_party_highertaxes_st "Perceived economic party position"
		label variable w7_party_highertaxes_stXeconMIP "Perceived economic party position X MIP economic"
		label variable w7_party_migrrestr_st "Perceived party position on immigration"
		label variable w7_party_migrrestr_stXmigrMIP "Perceived party position on immigration X MIP immigration"	
		label variable w7_dist_subj_econ_st "Perceived economic distance"
		label variable w7_dist_s_econXeconMIP "Perceived economic distance X MIP economic"
		label variable w7_dist_subj_migration_st "Perceived distance on immigration"
		label variable w7_dist_s_migrationXmigrMIP "Perceived distance on immigration X MIP immigration"
		label variable w7_dist_subj_leftright_st "Perceived distance on left-right"
		label variable w7_left_intensity "left (intensity)"
		label variable w7_right_intensity "right (intensity)" 
		label variable w7_party_lr_st "Perceived party left-righ position"
		label variable w7_party_lr_stXleft "Perceived party left-right position X left"
		label variable w7_party_lr_stXright "Perceived party left-right position X right"
			
	*** set data for choice model
		cmset personid obs_party 
